/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import java.util.List;
import model.Log;

import org.hibernate.Session;
import org.hibernate.Transaction;
import util.HibernateUtil;

/**
 *
 * @author Fran
 */
public class LogDAO {
    
    
    public LogDAO(){
       session = HibernateUtil.getSessionFactory().openSession();
    }
    
    private Session session;
    
    public void inserir(Log log)
    {
        
        Transaction t = session.beginTransaction();
        session.save(log);
        t.commit();
            
    }
    
    public List<Log> findAll(String usuario){
        
        String hql = "from Log order by logcodigo desc";
        
        //if(usuario.trim().isEmpty()){
       //     hql += " usucodigo like '%"+usuario+"%'";
        //}
        
        return session.createQuery(hql).list();
    }
    
}
